<?php
class About extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->helper ( 'url' );
		$this->load->library ( 'form_validation' );
	}
	
	function allList() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$this->load->model ( 'Mabout' );
			$data ['aboutList'] = $this->Mabout->getAboutListAll ();
			
			$data ['authority'] = $this->session->userdata ( 'authority' );
			$data ['adminName'] = $this->session->userdata ( 'adminName' );
			
			$this->load->view ( 'admin/header', $data );
			$this->load->view ( 'admin/nav' );
			$this->load->view ( 'admin/about_list' );
			$this->load->view ( 'admin/footer' );
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有编辑静态页面的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function delete() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$data ['id'] = $this->uri->segment ( 4, 0 );
			$this->load->model ( 'Mabout' );
			
			if ($this->Mabout->delAboutbyId ( $data ['id'] )) {
				$data ['msg'] = '静态页面删除成功！';
			} else
				$data ['msg'] = '静态页面删除失败！';
			
			$data ['url'] = base_url () . 'admin/about/allList';
			$this->load->view ( 'admin/admin_message', $data );
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有删除静态页面的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function add() {
		$this->load->model ( 'Mabout' );
		$this->load->helper ( 'form' );
		
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			
			$this->form_validation->set_rules ( 'name', '静态页名', 'trim|required|max_length[45]' );
			
			if ($this->form_validation->run () == TRUE) {
				$data ['name'] = $this->input->post ( 'name' );
				$data ['details'] = $this->input->post ( 'details' );
				$data ['updatePerson'] = $this->session->userdata ( 'adminName' );
				$data ['updateTime'] = date ( "Y/m/d H:i:s", time () );
				$data ['class']=$this->input->post ( 'class' );
				$data ['id'] = $this->Mabout->addAbout ( $data );
				if ($data ['id']) {
					$data ['msg'] = '静态页添加成功！';
				} else {
					$data ['msg'] = '数据插入失败！';
				}
				$data ['url'] = base_url () . 'admin/about/allList';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['form'] = array ('id' => 'aboutAddForm' );
				$data ['details'] = $this->input->post ( 'details' );
				
				$data ['authority'] = $this->session->userdata ( 'authority' );
				$data ['adminName'] = $this->session->userdata ( 'adminName' );
				
				$this->load->view ( 'admin/header', $data );
				$this->load->view ( 'admin/nav' );
				$this->load->view ( 'admin/about_add' );
				$this->load->view ( 'admin/footer' );
			}
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有添加常见问题的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function edit() {
	$this->load->model ( 'Mabout' );
		$this->load->helper ( 'form' );
		
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			
			$this->form_validation->set_rules ( 'name', '静态页名', 'trim|required|max_length[45]' );
			$this->form_validation->set_rules ( 'class', '分类', '' );
			
			$data ['id'] = $this->uri->segment ( 4, 0 );
			$data ['about'] = $this->Mabout->getAboutbyId ( $data ['id'] );
			
			if ($this->form_validation->run () == TRUE) {
				$query ['name'] = $this->input->post ( 'name' );
				$query ['details'] = $this->input->post ( 'details' );
				$query ['updatePerson'] = $this->session->userdata ( 'adminName' );
				$query ['class']=$this->input->post ( 'class' );
				
				if ($this->Mabout->updateAbout ($query,$data ['id'])) {
					$data ['msg'] = '静态页修改成功！';
				} else {
					$data ['msg'] = '数据更新失败！';
				}
				$data ['url'] = base_url () . 'admin/about/allList';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['details'] = $this->input->post ( 'details' );
				$data ['form'] = array ('id' => 'questionEditForm' );
				
				$data ['authority'] = $this->session->userdata ( 'authority' );
				$data ['adminName'] = $this->session->userdata ( 'adminName' );
				
				$this->load->view ( 'admin/header', $data );
				$this->load->view ( 'admin/nav' );
				$this->load->view ( 'admin/about_edit' );
				$this->load->view ( 'admin/footer' );
			}
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有修改常见问题的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
}